﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WJP.Domain.Entitys;
using WJP.Domain.Repositories;

namespace WJP.EntityFramework.Repositories
{
    public class EFRepositoryBase<TDbContext, TEntity, TPrimaryKey> :
        RepositoryBase<TEntity, TPrimaryKey>, IRepositoryWithDbContext, ISupportsExplicitLoading<TEntity, TPrimaryKey>
        where TEntity : class, IEntity<TPrimaryKey>
        where TDbContext : DbContext
    {
        private readonly IDbContextProvider<TDbContext> _dbContextProvider;

        public virtual TDbContext Context => _dbContextProvider.GetDbContext();

        public virtual DbSet<TEntity> Table => Context.Set<TEntity>();

        public Task EnsureCollectionLoadedAsync<TProperty>(TEntity entity, System.Linq.Expressions.Expression<Func<TEntity, IEnumerable<TProperty>>> collectionExpression, CancellationToken cancellationToken) where TProperty : class
        {
            throw new NotImplementedException();
        }

        public Task EnsurePropertyLoadedAsync<TProperty>(TEntity entity, System.Linq.Expressions.Expression<Func<TEntity, TProperty>> propertyExpression, CancellationToken cancellationToken) where TProperty : class
        {
            throw new NotImplementedException();
        }

        public override IQueryable<TEntity> GetAll()
        {
            return Table;
        }

        public DbContext GetDbContext()
        {
            return Context;
        }
    }
}
